<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="javascript:;">订单管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card class='box-card'>
      <!-- 搜索区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            class="input-with-select"
            clearable
            v-model="queryInfo.query"
            @clear='getOrderList'
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click='getOrderList'
            ></el-button>
          </el-input>
        </el-col>

      </el-row>
      <el-table
        :data="ordersList"
        border
        stripe
        style="width: 100%"
      >
        <el-table-column
          type="index"
          label="#"
        >
        </el-table-column>

        <el-table-column
          prop="order_number"
          label="订单编号"
        >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="pay_status"
          label="是否付款"
          width="100"
        >
          <template v-slot='{row}'>
            <el-tag
              v-if='row.order_pay=== "1"'
              effect="dark"
              size="mini"
            >已付款
            </el-tag>
            <el-tag
              v-else-if='row.order_pay=== "0"'
              type='warning'
              effect="dark"
              size="mini"
            >未付款
            </el-tag>

          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间"
        >
          <template v-slot="{row}">
            {{row.create_time | dateFormat('YYYY-MM-DD HH:mm:ss')}}

          </template>
        </el-table-column>
        <el-table-column
          prop=""
          label="操作"
        >
          <template v-slot="{}">
            <div>
              <el-button
                type="primary"
                icon='el-icon-edit'
                size="mini"
                @click="addressVisible=true"
              ></el-button>
              <el-button
                type="success"
                icon="el-icon-location-outline"
                size="mini"
                @click='showProgressBox'
              ></el-button>

            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页模块 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressVisible"
      width="50%"
      @close='addressDialogClosed'
    >
      <el-form
        :model="addressForm"
        ref="addressFormRef"
        label-width="100px"
        :rules="addressFormRules"
      >
        <el-form-item
          label="省市区/县"
          prop='address1'
        >
          <el-cascader
            v-model="addressForm.address1"
            :options="addressList"
            :props="cascaderProps"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item
          label="详细地址"
          prop='address2'
        >
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>

      </el-form>

      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="addressVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息对话框 -->
    <el-dialog
      title="物流信息"
      :visible.sync="progressVisible"
      width="50%"
    >
      <!-- 物流信息  -->
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in progressInfo"
          :key="index"
          :timestamp="item.time"
        >
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="progressVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import addressList from './citydata.js';
export default {
  props: [],
  data () {
    return {
      // 查询条件
      queryInfo:{
        query:'',
        pagenum:1,
        pagesize:10
      },
      // 订单总条数 
         total:0,
      // 订单列表
      ordersList:[],
      // 修改功能数据--------------------------------------
      // 修改地址对话框开关
      addressVisible:false,
      // 修改地址表单
      addressForm: {
        address1:[],
        address2:'',
      },
      // 地址规则
     addressFormRules:{
        address1:[{required:true, message:'请选中省市区县',trigger: 'blur'}],
        address2:[{required:true, message:'请填写详细地址',trigger: 'blur'}]
      },
 // 指定级联选择器的配置项
cascaderProps: {
        expandTrigger:'hover',
        checkStrictly:true,
         },
    // 级联选择器可选项数据源
          addressList:addressList,
//  物流进度的数据-------------------------------
progressVisible:false,
// 物流信息
progressInfo:[]
    }
  },
  mounted () {
this.getOrderList()
  },
  methods: {
// 获取订单列表数据
 async getOrderList(){
   const { data: res } = await this.$http.get('orders',{params:this.queryInfo})
  if(res.meta.status !== 200){return this.$message.error('获取订单列表失败')}
  this.ordersList =res.data.goods
  this.total = res.data.total
  //  console.log(res.data.goods[0]);
},
handleSizeChange(val){
this.queryInfo.pagesize=val;
this.getOrderList()
},
handleCurrentChange(val){
this.queryInfo.pagenum=val;
this.getOrderList()
},
// 关闭adress对话框执行的函数
addressDialogClosed(){
  this.$refs.addressFormRef.resetFields()
},
// 物流进度对话框打开
async showProgressBox(){
  this.progressVisible=true
  const { data: res } = await this.$http.get(`/kuaidi/3`)
  // console.log(res);
  if(res.meta.status !== 200){return this.$message.error('获取物流信息失败')}
    this.progressInfo = res.data;

  },
   // 级联选择框修改数据时触发
      handleChange(){
        
      }
  }
}
</script>
<style lang="less" scoped>
.el-cascader{
  width: 100%;
}
</style>